/// <summary>
// CodeFx.MySqlProviders - .NET Providers for MySql using the framework CodeFx
// Laurent Morisseau
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Laurent Morisseau
/// </summary>
/// <author><a href="mailto:laurent.morisseau@gmail.com">Laurent Morisseau</a></author>


namespace CodeFx.MySqlProviders
{
    using System;
    using System.Collections;
    using System.Globalization;
    using System.Web;
    using System.Web.Util;
    using System.Web.UI.WebControls.WebParts;

    internal static class PersonalizationProviderHelper
    {
        internal static string[] CheckAndTrimNonEmptyStringEntries(string[] array, string paramName, bool throwIfArrayIsNull, bool checkCommas, int lengthToCheck)
        {
            if (array == null)
            {
                if (throwIfArrayIsNull)
                {
                    throw new ArgumentNullException(paramName);
                }
                return null;
            }
            if (array.Length == 0)
            {
                throw new ArgumentException("PersonalizationProviderHelper_Empty_Collection");
            }
            string[] textArray1 = null;
            for (int num1 = 0; num1 < array.Length; num1++)
            {
                string text1 = array[num1];
                string text2 = (text1 == null) ? null : text1.Trim();
                if (string.IsNullOrEmpty(text2))
                {
                    throw new ArgumentException("PersonalizationProviderHelper_Null_Or_Empty_String_Entries");
                }
                if (checkCommas && (text2.IndexOf(',') != -1))
                {
                    throw new ArgumentException("PersonalizationProviderHelper_CannotHaveCommaInString");
                }
                if ((lengthToCheck > -1) && (text2.Length > lengthToCheck))
                {
                    throw new ArgumentException("PersonalizationProviderHelper_Trimmed_Entry_Value_Exceed_Maximum_Length");
                }
                if ((text1.Length != text2.Length) && (textArray1 == null))
                {
                    textArray1 = new string[array.Length];
                    Array.Copy(array, textArray1, num1);
                }
                if (textArray1 != null)
                {
                    textArray1[num1] = text2;
                }
            }
            if (textArray1 == null)
            {
                return array;
            }
            return textArray1;
        }

        internal static string CheckAndTrimStringWithoutCommas(string paramValue, string paramName)
        {
            string text1 = StringHelper.CheckAndTrimString(paramValue, paramName);
            if (text1.IndexOf(',') != -1)
            {
                throw new ArgumentException("PersonalizationProviderHelper_CannotHaveCommaInString");
            }
            return text1;
        }

        internal static void CheckNegativeInteger(int paramValue)
        {
            if (paramValue < 0)
            {
                throw new ArgumentException("PersonalizationProviderHelper_Negative_Integer");
            }
        }

        internal static void CheckNegativeReturnedInteger(int returnedValue)
        {
            if (returnedValue < 0)
            {
                throw new HttpException("PersonalizationAdmin_UnexpectedPersonalizationProviderReturnValue");
            }
        }

        internal static void CheckNullEntries(ICollection array, string paramName)
        {
            if (array == null)
            {
                throw new ArgumentNullException(paramName);
            }
            if (array.Count == 0)
            {
                throw new ArgumentException("PersonalizationProviderHelper_Empty_Collection");
            }
            IEnumerator enumerator1 = array.GetEnumerator();
            try
            {
                while (enumerator1.MoveNext())
                {
                    if (enumerator1.Current == null)
                    {
                        throw new ArgumentException("PersonalizationProviderHelper_Null_Entries");
                    }
                }
            }
            finally
            {
                IDisposable disposable1 = enumerator1 as IDisposable;
                if (disposable1 != null)
                {
                    disposable1.Dispose();
                }
            }
        }

        internal static void CheckOnlyOnePathWithUsers(string[] paths, string[] usernames)
        {
            if (((usernames != null) && (usernames.Length > 0)) && ((paths != null) && (paths.Length > 1)))
            {
                throw new ArgumentException("PersonalizationProviderHelper_More_Than_One_Path");
            }
        }

        internal static void CheckPageIndexAndSize(int pageIndex, int pageSize)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentException("PersonalizationProviderHelper_Invalid_Less_Than_Parameter");
            }
            if (pageSize < 1)
            {
                throw new ArgumentException("PersonalizationProviderHelper_Invalid_Less_Than_Parameter");
            }
            long num1 = ((pageIndex * pageSize) + pageSize) - 1;
            if (num1 > 0x7fffffff)
            {
                throw new ArgumentException("PageIndex_PageSize_bad");
            }
        }

        internal static void CheckPersonalizationScope(PersonalizationScope scope)
        {
            if ((scope < PersonalizationScope.User) || (scope > PersonalizationScope.Shared))
            {
                throw new ArgumentOutOfRangeException("scope");
            }
        }

        internal static void CheckUsernamesInSharedScope(string[] usernames)
        {
            if (usernames != null)
            {
                throw new ArgumentException("PersonalizationProviderHelper_No_Usernames_Set_In_Shared_Scope");
            }
        }

    }
}

